package com.apes.hr.cultivate.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.hr.base.model.Employee;
import com.apes.hr.base.model.Job;
import com.apes.hr.base.model.Rank;
import com.apes.hr.base.model.WorkPost;
import com.apes.scm.masterdata.frame.model.Branch;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 参训人员名单
 * @author Linwz
 * @create 2019-06-18 10:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CultivatePlanArrangeItem.CONST_TABLE_NAME)
public class CultivatePlanArrangeItem extends Model {
    public static final String CONST_TABLE_NAME = "hr_cultivate_plan_arrange_item";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "培训计划安排")
    @Comment("培训计划安排编码")
    private String id;   //培训计划安排编码

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "cultivate_plan_arrange_id", referencedColumnName = "ID")
    @Comment("培训计划安排")
    private CultivatePlanArrange cultivatePlanArrange; //培训计划安排

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "employee_id", referencedColumnName = "id")
    @Comment("人员编码")
    private Employee employeeId; //人员编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "branch_id", referencedColumnName = "id")
    @Comment("部门")
    private Branch branch; // 部门

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "job_id", referencedColumnName = "id")
    @Comment("职位")
    private Job job; //职位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_id", referencedColumnName = "id")
    @Comment("岗位")
    private WorkPost workPost; // 岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rank_id", referencedColumnName = "id")
    @Comment("职级")
    private Rank rankId; // 职级

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "entry_date")
    @Comment("入职日期")
    private Date entryDate;  //入职日期

    @Column(name = "duration")
    @Comment("入职时长")
    private int duration;//入职时长


}
